﻿<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@page import="global.Constants"%>
    <%@page import="util.ServletHelp"%>
     <%@page import="com.aiflow.Action.DepartmentAction"%>
<%@page import="com.aiflow.Action.DictionaryAction;"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
	<%
		String baseUrl = request.getContextPath();
	%>
	<script type="text/javascript">
	Ext.chart.Chart.CHART_URL = '<%=baseUrl %>/js/ext-3.3.0/resources/charts.swf';
	    //这里的全局是为了修改之后的刷新
	    var superviseQueryListGrid;
	    var superviseQueryListStore;
	    var searchSuperviseWindow;
		$(document).ready(function(){
			 // 全局参数
			var baseParams = {limit:<%=Constants.PAGE_SIZE %>,start : 0,superviseStatus : 1};
			var EXT_QUERY_TIME_OUT = 1200000;

			// 传报数据源  userName,u.telep ,d.name as targetName
		    superviseQueryListStore = new Ext.data.JsonStore({
		        url: '${pageContext.request.contextPath}/findSupervise.action',
		        root: 'datas',
				timeout : EXT_QUERY_TIME_OUT,
		        totalProperty: 'results',
		        fields: ['id','Supervise_id','Region_name','Supervise_time','Supervise_user','work_level','work_title','work_time','supervise_status','send'],
		        baseParams: baseParams,
		        autoLoad: true,
				listeners : {  
                load : function() {  
              isDetailReady = true;// 查询置换标志为已查过   
            }  
            }  
		    });
		    
		      // 区域  数据源  getDepartmentCombo
	          var regionStore = new Ext.data.ArrayStore({  
	            fields : ['region_id', 'region_name'],  
	            data : <%=DepartmentAction.getDepartmentNameCombo("1")%>,
	            sortInfo: {field: "region_id", direction: "ASC"}
	        });
		    
		    //   工单发送状态
	        var superviseStore = new Ext.data.ArrayStore({  
                    fields : ['status', 'statusName'],  
		            data : <%=ServletHelp.getArrayFromMap(Constants.ALARM_SEND_MAP, null)%>,
		            sortInfo: {field: "status", direction: "ASC"}
	        });
	       
	        //督办状态
	        var superviseQueryStore = new Ext.data.ArrayStore({  
                    fields : ['superviseQuery', 'superviseQueryName'],  
		            data : <%=ServletHelp.getArrayFromMap(Constants.Supervise_STATUS_MAP, null)%>,
		            sortInfo: {field: "superviseQuery", direction: "ASC"}
	        });
	        
	        //工单状态
	        var superviseType = new Ext.data.ArrayStore({  
                    fields : ['superviseType', 'superviseTypeName'],  
		            data : <%=ServletHelp.getArrayFromMap(Constants.Supervise_STATUS_MAP, null)%>,
		            sortInfo: {field: "superviseType", direction: "ASC"}
	        });
	     
			 var superviseStatusCombo = new Ext.form.ComboBox({
				id :'superviseStatusCombo', 
			    hiddenName: 'superviseStatus',
				triggerAction: 'all', 
				typeAhead: true, 
				store: superviseStore, 
				mode : 'local',
				valueField: 'status', 
				displayField: 'statusName', 
				editable: true, 
				lazyRender: true,
				allowBlank:false
			});
			
			var supervisestatusQueryCombo = new Ext.form.ComboBox({
				id :'supervisestatusQueryCombo', 
				//   hiddenName: 'supervisestatusQueryCombo',
				triggerAction: 'all', 
				typeAhead: true, 
				store: superviseQueryStore, 
				mode : 'local',
				valueField: 'superviseQuery', 
				displayField: 'superviseQueryName', 
				editable: true, 
				width:100,
				lazyRender: true,
				allowBlank:true
			});
			
			var supervisetypeQueryCombo = new Ext.form.ComboBox({
				id :'supervisetypeQueryCombo', 
				triggerAction: 'all', 
				typeAhead: true, 
				store: superviseType, 
				mode : 'local',
				valueField: 'superviseType', 
				displayField: 'superviseTypeName', 
				editable: true, 
				width:100,
				lazyRender: true,
				allowBlank:true
			});
			  
		       // 工单类型  数据源  getDepartmentCombo  （一级告警）
	           var superviseTypeStore = new Ext.data.ArrayStore({  
                    fields : ['superviseTyid', 'superviseTyname'],  
		            data : <%=DictionaryAction.getDictionaryCombo("741")%>,
		            sortInfo: {field: "superviseTyid", direction: "ASC"}
	           });
	        
	        	var superviseTyCombo = new Ext.form.ComboBox({
				id :'superviseTy', 
			    //hiddenName: 'superviseTy',
				triggerAction: 'all', 
				typeAhead: true, 
				store: superviseTypeStore, 
				mode : 'local',
				valueField: 'superviseTyid', 
				displayField: 'superviseTyname', 
				editable: true, 
				lazyRender: true,
				allowBlank:false
			});
		 
		   // 工具栏
		   var superviseQueryListToolbar = new Ext.Toolbar({
		    	renderTo: 'superviseQueryListToolBarDiv',
		    	items: [
					new Ext.Button({
					    id: 'supervise-export-button',
					    text: '工单导出',
						iconCls: 'page_white_excel'
					}),'-',
					new Ext.Button({
					    id: 'supervise-search-button',
					    text: '通话记录',
						iconCls: 'note_edit'
					}),
					'-','查询：','区域',
					{  
			                xtype:'combo',
			                id:'regionn',
			                hiddenName: 'region',
			                fieldLabel: '省市',
			                store: regionStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'region_id',
			                displayField: 'region_name',
			                allowBlank:true,
			                editable: false,
			                width: 100,
			                anchor:'98%'
			           },
			             '&nbsp;&nbsp;督办状态',
			              supervisestatusQueryCombo,
			                '-','派单时间：',' 起',
					   {  
			                xtype:'datefield',
			                id:'superviseStartTime',
			                hiddenName: 'startTime',
			                fieldLabel: '开始',
                            format:'Y-m-d',
			                mode : 'local',
			                triggerAction: "all",
			                allowBlank:true,
			                editable: false,
			                width: 100,
							vtype : 'daterange',
			                anchor:'98%',
							endDateField : 'superviseEndTime'
			           },' 止 ',
			           {  
			                xtype:'datefield',
			                id:'superviseEndTime',
			                hiddenName: 'endTime',
			                fieldLabel: '开始',
                            format:'Y-m-d',
			                mode : 'local',
			                triggerAction: "all",
			                allowBlank:true,
			                editable: false,
							vtype : 'daterange',
			                width: 100,
			                anchor:'98%',
							startDateField : 'superviseStartTime'
			           },'-',
		                {// 工单标题
			                xtype:'textfield',
			                id:'supervise_title',
			                name: 'supervise_title',
			                emptyText: '请输入工单标题名称',
			                anchor:'98%',
			                width: 120,
			                maxLength: 20
			           },
		             new Ext.Button({
					    id: 'supervise-query-button',
					    text: '查询',
						iconCls: 'magnifier'
					})
				]
			});

			// 数据表格    dept_name spec
			var sm = new Ext.grid.CheckboxSelectionModel();
			superviseQueryListGrid = new Ext.grid.EditorGridPanel({
				id: 'superviseQueryListGrid',
				renderTo: 'superviseQueryListGridDiv',
				border: false,
				stateful: true,
			    autoScroll: 'auto',
		        store: superviseQueryListStore,
		        loadMask: true,
		        cm: new Ext.grid.ColumnModel({
		            defaults: {
		                width: 100,
		                sortable: true
		            },
			        columns: [
						sm,
					    new Ext.grid.RowNumberer({header:'№',width:50}),
						{id:'id',header: '用户ID', width: 100, hidden: true, sortable: true, dataIndex: 'id'},
						{id:'Supervise_id',header: '工单编号', width: 130, hidden: false, sortable: true , dataIndex: 'Supervise_id'},
						{id:'Supervise_time',header: '派单时间', width: 100, hidden: false, sortable: true , dataIndex: 'Supervise_time'},
			            {id:'Region_name',header: '地市', width: 100,hidden: false, sortable: true, dataIndex: 'Region_name'},
			            {id:'Supervise_user',header: '派单对象', width: 230,hidden: false, sortable: true, dataIndex: 'Supervise_user'},
			            {id:'work_level',header: '工单级别', width: 200,hidden: false, sortable: true, dataIndex: 'work_level'},
			            {id:'work_title',header: '工单标题', width: 100,hidden: false, sortable: true, dataIndex: 'work_title'},
                        {id:'work_time',header: '工单历时', width: 150,hidden: false, sortable: true, dataIndex: 'work_time'},
			            {id:'supervise_status',header: '工单状态', width: 120,hidden: false, sortable: true, dataIndex: 'supervise_status',renderer: function(value, cellmeta,record){return typeComboRenderer(value, cellmeta,record);}},
			            {id:'send',header: '发送状态', width: 120,hidden: false, sortable: true, dataIndex: 'send',renderer: function(value, cellmeta,record){return statusComboRenderer(value, cellmeta,record);}}
			            ]
		        }),
		        sm: sm,
		        columnLines: true,
		         bbar: new Ext.PagingToolbar({
					pageSize: <%=Constants.PAGE_SIZE %>,
					store: superviseQueryListStore,
					displayInfo: true,
					displayMsg: Anynote.PAGINGTOOLBAR_DISPLAYMSG,
					emptyMsg: Anynote.PAGINGTOOLBAR_EMPTYMSG,
					doLoad: function(start){
                        baseParams.start = start;
						var reg = Ext.getCmp("regionn").getValue();
			            var status = Ext.getCmp("supervisestatusQueryCombo").getValue();
			            var startTime = Ext.getCmp("superviseStartTime").getValue();
					    var endTime = Ext.getCmp("superviseEndTime").getValue();
					    var superviseTitle = Ext.getCmp("supervise_title").getValue();
			            baseParams.region = reg;
			            baseParams.superviseStatus = status;
			            baseParams.startTime = startTime;
				        baseParams.endTime = endTime;
				        baseParams.superviseTitle = superviseTitle;
						this.store.load({params: baseParams});
					}
		        }),
		        listeners:{
		         rowdblclick:function(grid,rowIndex,event){
		          dx(grid,rowIndex,event);
		        }
		        }
		    });

			// 设置Grid高度和宽度
		    Anynote.resizeGridTo("superviseQueryListGrid", 0, 56);
		    
		    // 类型ComboBox设值  
			function statusComboRenderer(value, cellmeta,record){
				var index = superviseStore.find(Ext.getCmp('superviseStatusCombo').valueField,value);
				var record = superviseStore.getAt(index);
				var displayText = "";
				if(record==null){
					displayText = value;
				}else{
					displayText = record.data.statusName;
				}
				return displayText;
			}
			
			// 类型ComboBox设值  
			function typeComboRenderer(value, cellmeta,record){
				var index = superviseStore.find(Ext.getCmp('superviseTyCombo').valueField,value);
				var record = superviseStore.getAt(index);
				var displayText = "";
				if(record==null){
					displayText = value;
				}else{
					displayText = record.data.superviseTypeName;
				}
				return displayText;
			}
		})  
	
			 $("#supervise-query-button").click(function(){
			    // superviseQueryListStore
			   var reg = Ext.getCmp("regionn").getValue();
			   var status = Ext.getCmp("supervisestatusQueryCombo").getValue();
			   var startTime = Ext.getCmp("superviseStartTime").getValue();
			   var endTime = Ext.getCmp("superviseEndTime").getValue();
			   var superviseTitle = Ext.getCmp("supervise_title").getValue();
			     var basePar  = {limit:<%=Constants.PAGE_SIZE %>,start : 0};
			       basePar.region = reg;
			       basePar.superviseStatus = status;
			       basePar.startTime = startTime;
			       basePar.endTime = endTime;
			       basePar.superviseTitle = superviseTitle;
			    superviseQueryListStore.reload({params:basePar});
			 })
		
			     // 查看拨打记录
				$("#supervise-search-button").click(function(){
				    var records = superviseQueryListGrid.getSelectionModel().getSelections();
				    if(records.length < 1){
					 Ext.Msg.alert("提示", "请至少选择一条数据.");
				    }else{
				     var superviseIds = "";
				     superviseIds = records[0].get("snumbe");
				     //只能一条一条的查看，不能多个一起查看
					 if(records.length == 1){
					    searchSuperviseWindow = new Ext.Window({
								title: '查看通话记录',
								width: 800,
								height: 400,
								modal: true,
								maximizable: false,
								resizable: false,
								layout:'fit',
								iconCls: 'note_edit',
								plain: true,
								autoLoad:{url:'${pageContext.request.contextPath}/page/bussmodule/superviseQuery/searchSuperviseQueryConfig.jsp?superviseIds='+superviseIds,scripts:true,nocache:true}
								});
								searchSuperviseWindow.show();
					 }else{
					   Ext.Msg.alert("提示", "只能选择一条数据.");
					 }
				    }
				});

			     $("#supervise-export-button").click(function(){   //   下载 
				  var reg = Ext.getCmp("regionn").getValue();
			      var status = Ext.getCmp("supervisestatusQueryCombo").getValue();
			          window.location.href = "${pageContext.request.contextPath}/alarm_supervisedown.action?region="+reg+"&superviseStatus="+status;
				  })	
				  
		    // 柱状图
	        // 拨打统计按钮
			function dx(grid,rowIndex,event){
		    var selectionModel = grid.getSelectionModel();    
            var record = selectionModel.getSelected();
            var superviseid = record.get("Supervise_id");
			Anynote.ajaxRequest({
						baseParams: {superviseid:superviseid},
						action: '${pageContext.request.contextPath}/heraldRecord_sendCountSupervise.action',
						callback: function(jsonResult){
						   var superviseTarget = [];
						   var supervise = new Array();
						   var sj = jsonResult.datas ;
						   for(var i=0;i<sj.length;i++){
						      var supervise = new Array();
						      var al = sj[i];
						      supervise.push(al.name);
						      supervise.push(al.count);
						      superviseTarget.push(supervise);
						   }
								var accountListInOutStore = new Ext.data.ArrayStore({
							        fields: ['sendcount', 'herald'],
							        data: superviseTarget                     
							    });
								 // 拨打次数统计窗口
								var groupInOutWindow = new Ext.Window({
									title: '语音发送情况',
									width: 600,
									height: 350,
									modal: true,
									maximizable: false,
									resizable: false,
									layout:'fit',
									plain: true,
                                    iconCls: 'chart_bar',
									items: {
								    	xtype: 'columnchart',
							            store: accountListInOutStore,
							            yField: 'herald',
							            xField: 'sendcount',
							            xAxis: new Ext.chart.CategoryAxis({
							                title: '传报对象'
							            }),
							            yAxis: new Ext.chart.NumericAxis({
											maximum:50,
											minimum:0,
							                title: '拨打电话次数'
							            }),
							            extraStyle: {
							               xAxis: {
							                    labelRotation: 0
							                },
						                   yAxis: {
							                    labelRotation: 0
							                }
							            }
							        }
								}).show();
				}
				})
			};				     
	</script>
</head>
<body>
<div id="superviseQueryListDiv">
	<div id="superviseQueryListToolBarDiv"></div>
	<div id="superviseQueryListGridDiv" style="width:100%;height:100%;"></div>
</div>
</body>
</html>